/**
 * Created by zhongb on 2017/4/11.
 */
var $ = require('jquery');
require('easyui');
var $alert = require('libs/alert');
$(function () {
    //获取url参数
    var orderId = $.getUrlParam("id");
    var status = {
        unsaved: '未保存',
        uncommit: '未提交',
        commit: '已提交',
        recieved: '已收货',
        processed: '已处理',
        processing: '处理中',
        shelveing: '上架中',
        invalid: '已取消'
    };
    fillData(orderId);
    function fillData(orderId) {
        $.get('api/v1/p/mms/outRoomOrder/load',{id: orderId},function (res) {
            if(res.code == 200){
                var data = res.data;
                var $firstTarget = $("#baseInfo").find("span");
                var $secondTarget = $("#receiveInfo").find("span");
                //元素赋值
                $firstTarget.eq(0).text(data.orderNo);
                $firstTarget.eq(1).text(data.entName);
                $firstTarget.eq(2).text(data.warehouseName);
                $firstTarget.eq(3).text(data.platType);
                $firstTarget.eq(4).text(data.shopName);
                $firstTarget.eq(5).text(data.platOrderNo);
                $firstTarget.eq(6).text(data.deliveryWayName);
                $firstTarget.eq(7).text(data.deliveryCode);
                $secondTarget.eq(0).text(data.recipientName);
                $secondTarget.eq(1).text(data.recipientCountryName);
                $secondTarget.eq(2).text(data.recipientRegionName);
                $secondTarget.eq(3).text(data.recipientCityName);
                $secondTarget.eq(4).text(data.recipientZipcode);
                $secondTarget.eq(5).text(data.recipientAddress1);
                $secondTarget.eq(6).text(data.recipientPhone);
                $secondTarget.eq(7).text(data.recipientEmail);
                tableInit(orderId);
            }else{
                $alert(res.message);
            }
        });
    }
    function tableInit(orderId) {
        $("#mainTable").datagrid({
            url:'api/v1/p/mms/outRoomOrder/goodsList',
            border: false,
            pagination: true,
            pageSize: 10,
            pageList: [10, 20, 50, 100],
            singleSelect: true,
            rownumbers: true,
            emptyMsg: '暂无数据',
            queryParams: {
                orderId: orderId
            },
            columns:[[
                {
                    field : 'code',
                    title : '商品编码',
                    width : '25%'
                },{
                    field : 'chName',
                    title : '中文名称',
                    width : '25%'
                },{
                    field : 'nums',
                    title : '数量',
                    width : '25%'
                },{
                    field : 'weightKg',
                    title : '重量(Kg)',
                    width : '25%'
                }
                ]],
            onClickRow: function (rowIndex, rowData) {
                $(this).datagrid('unselectRow', rowIndex);
            },
            loadFilter:function(data){
                if(data.code == '200'){
                    return data.data;
                }else{
                    return [];
                }
            }
        });
    }
});
